<template>
	<view class="box" :style="{backgroundImage:'url(' + img + ')'}">
		<u-icon size="40" class="icon" name="arrow-left" color="white" @click="toBack"></u-icon>
		<view class="content_box">
			<rich-text :nodes="info" v-if="info"></rich-text>
		</view>
		<view v-if="!is" class="btn" @click="pay">加入会员</view>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				info:'',
				is:'',
				img:'',
				config:{}
			}
		},
		onShow() {
			this.getIs();
		  this.getInfo();	
		},
		methods:{
			getIs(){
				let form={};
				form.token=uni.getStorageSync('userToken');
				this.$get(this.$api.uInfo,form,res=>{
					let {data}=res;
					this.is=data.data;
				})
			},
			pay(){
				let form={};
				form.token=uni.getStorageSync('userToken');
				let _=this;
				this.$post(this.$api.uPay,form,res=>{
					let {data} = res;
					if(data.code==1){
						
						if(data.msg==1){
							uni.requestPayment({
								provider: 'wxpay',
								timeStamp: data.data.timeStamp,
								nonceStr: data.data.nonceStr,
								package: data.data.package,
								signType: data.data.signType,
								paySign: data.data.paySign,
								success: function(res) {
									_.$Toast('支付成功');
									setTimeout(()=>{
										uni.navigateBack();
									},1000);
								},
								fail: function(err) {
									_.$Toast('支付取消');
								}
							});
						}else{
							_.$Toast(data.msg);
							setTimeout(()=>{
								uni.navigateBack();
							},1000);
						}
						
						
					}else{
						_.$Toast(data.msg);
					}
				});
			},
			getInfo(){
			  this.$get(this.$api.kcConfig,{},res=>{
				   let {data}=res;
				   
				   let info=data.data;
				   
				   if (info.hyqy) {
				   	info.hyqy = this.$formatRichText(info.hyqy).replace(/src="\//g,
				   		'src="' + getApp().globalData
				   		.imgRemote + '/');
				   }
				   
					this.info=info.hyqy;
					this.img=info.hyimg;
					this.config=info;
			  });	
			},
		toBack(){
			uni.navigateBack();
		}
		},
		onShareAppMessage() {
			let obj = {};
			if (this.config.hyname) {
				obj.title = this.config.hyname;
			}
			if (this.config.hyfximg) {
				obj.imageUrl = this.config.hyfximg;
			}
			return obj
		},
	}
</script>

<style lang="scss" scoped>
	.box{
	
		background-size: 100% 100%;
		background-repeat: no-repeat;
		width: 100%;
		min-height: 100vh;
	}
	.icon{
		padding: 90rpx 0 0 40rpx;
	}
	.content_box{
		box-sizing: border-box;
		padding: 38vh 65rpx 0 65rpx;
		line-height: 35.5rpx;
		font-size: 25rpx;
	}
	.btn {
	    position: fixed;
	    bottom: 50rpx;
	    left: 5%;
		width: 90%;
		box-sizing: border-box;
		padding: 15rpx;
		text-align: center;
		color: #F24110;
		background-image: linear-gradient(#F8E2B3, #F9B351);
		font-size: 32rpx;
		border-radius: 20rpx;
	}
</style>